﻿@{
    ViewBag.Title = "请选择拒赔原因";
    var id = Model != null ? Model.ID : 0;
}
@using ZBJF.Warranty.Common.Enums.InsuranceWarranty
@using ZBJF.Warranty.WebProvider
@using ZBJF.Warranty.Common.Enums.InfoCollect
@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.Common.Enums.Base
@using ZBJF.Warranty.Common.Enums.System
@model ZBJF.Warranty.Model.InsuranceWarrantyRecord
@{
    var cellPhoneInsuranceInfo = ServiceFactory.CellPhoneInsuranceInfoServiceInstance.Load(
        Model.InsuranceOrderServiceProjectId ?? 0);
    var cellPhoneServiceProjectID = cellPhoneInsuranceInfo != null && cellPhoneInsuranceInfo.CellPhoneServiceProjectID.HasValue
        ? cellPhoneInsuranceInfo.CellPhoneServiceProjectID.Value
        : 0;
    var serviceProjectType = (ServiceProductType)(Model.ServiceProjectType ?? 0);

    var infoCollectItems = ServiceFactory.InsuranceProductInfoCollectItemSnapshootServiceInstance.GetInsuranceProductInfoCollectItemSnapshoot(cellPhoneServiceProjectID, serviceProjectType, (byte)CollectWithType.RefuseInvoice).ToList();
    //如果快照不存在，去产品配置中取
    if (!infoCollectItems.Any())
    {
        infoCollectItems = ServiceFactory.InsuranceProductsInfoCollectItemMappingsServiceInstance.LoadInfoCollectItems(new List<int> { cellPhoneServiceProjectID }, (byte)CollectWithType.RefuseInvoice);
    }    
}
     @Html.AntiForgeryToken()
    @Html.HiddenFor(m => m.ID)
    <label>拒赔状态备注:</label>
    @Html.DropDownList("StatusReasonCancel",ConvertToSelector.Instance.StatusReasonConvertToSelectList(true,((byte)InsuranceWarrantyStatus.Refuse)))
    <div id="myTabContent" class="tab-content">
        <table id="tb" class="table table-bordered">
            <thead>
            <tr>
                <th>资料类型</th>
                <th>已上传图片数</th>
                <th>查看图片</th>
                <th>上传人</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            @for (int i = 0; i < infoCollectItems.Count; i++)
            {
                var infoCollectItem = infoCollectItems[i];
                var hasCollectItem = ServiceFactory.InsuranceWarrantyRecordInfoCollectServiceInstance.Load(Model.ID, (byte) CollectWithType.RefuseInvoice, infoCollectItem.InfoCollectItemID);
                var uploadFiles = ServiceFactory.UploadFilesServiceInstance.GetFiles(NeedUploadFileDataTableEnums.InsuranceWarrantyRecordInfoCollect, hasCollectItem != null ? hasCollectItem.ID : 0);
                var imageUrls = uploadFiles.Any() ? uploadFiles.Select(o => o.FilePath).ToList().Aggregate(string.Empty, (c, d) => c + ';' + d).Trim(';') : "";
                <tr>
                    <td>@infoCollectItem.InfoCollectItemName</td>
                    <td>@(hasCollectItem != null ? hasCollectItem.HadUploadPicCount : 0)</td>
                    <td>@if (hasCollectItem != null)
                        {
                            <a class='Edit-R' href='javascript:void(0);' onclick="showImageLayer(this, 'MultiImageLook.html')" imgurl="@(imageUrls)">
                                查看图片
                            </a>
                        }
                    </td>
                    <td>@(hasCollectItem != null ? hasCollectItem.CreateBy : "")</td>
                    <td>
                        <a class='Edit-R' href='javascript:void(0);' onclick='showLayerOpen("信息收集", "/PubModelDialog/InfoCollectDialog?ID=@(hasCollectItem != null ? hasCollectItem.ID : -1)&amp;InsuranceWarrantyRecordID=@Model.ID&amp;InfoCollectWith=@((byte) CollectWithType.RefuseInvoice)&amp;InfoColectItemID=@(infoCollectItem.InfoCollectItemID)&amp;InfoColectItemName=@(infoCollectItem.InfoCollectItemName)&amp;NeedUploadPicCount=@(infoCollectItem.CanUploadPicCount)", "500px", "350px")'>
                            上传图片
                        </a>
                    </td>
                </tr>
            }
            </tbody>
        </table>
    </div>
<div class="form-actions text-center">
    <input class="btn btn-primary Edit-R" type="submit" value="确定" onclick="UpdateInsuranceWarrantyRecordStatus()">
    <input class="btn" type="button" value="取消" id="btnCancel" onclick="parent.layer.closeAll()" />
</div>
<script>
    //取消报案点击确定后修改状态
    function UpdateInsuranceWarrantyRecordStatus() {
        var statusReasonId = $("#StatusReasonCancel").val();
        if (!statusReasonId) {
            layer.alert("请选择拒赔状态备注");
        }
        var stauts = @((byte) InsuranceWarrantyStatus.Refuse);
        var collectWithType = @(ViewBag.infoCollectWithType);
        var auditProjectType = @(ViewBag.auditProjectType);
        $.ajax({
            url: "/ToBeMaintainWorkOrder/UpdateInsuranceWarrantyRecordStatus?ID=" + @Model.ID,
            dataType: "json",
            type: "post",
            data: { statusReasonId: statusReasonId, status: stauts,infoCollectWithType:collectWithType,auditProjectType:auditProjectType},
            success: function(data) {
                if (data.Result) {
                    layer.alert(data.Message);
                    return;
                }
            }
        });
    }
</script>